//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chris.serve;

import com.alibaba.fastjson.JSONObject;
import com.chris.impl.menuImpl;
import com.chris.utils.DbConnection;
import com.chris.utils.JsonProcess;
import com.chris.utils.LogUtil;
import com.chris.utils.judgeNull;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet({"/registerMenu"})
public class registerMenu extends HttpServlet {
    private final menuImpl dao = new menuImpl();

    public registerMenu() {

    }

    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        JSONObject read = JsonProcess.read(req.getInputStream());
        PrintWriter writer = resp.getWriter();
        DbConnection.begin();

        try {
            String journal_title = (String)read.get("journal_title");
            String cn = (String)read.get("CN");
            String issn = (String)read.get("ISSN");
            String public_cycle = (String)read.get("public_cycle");
            String sponsor = (String)read.get("sponsor");
            String public_area = (String)read.get("public_area");
            if (!judgeNull.isNull(journal_title, cn, issn, public_cycle, public_area, sponsor)) {
                try {
                    this.dao.insert(journal_title, cn, issn, public_cycle, public_area, sponsor);
                    writer.print(JsonProcess.respSuccess("添加成功", null));
                    DbConnection.commit();
                } catch (Exception var12) {
                    var12.printStackTrace();
                    writer.print(JsonProcess.respError("参数错误"));
                    DbConnection.rollBack();
                }
            } else {
                writer.print(JsonProcess.respError("参数错误"));
                DbConnection.rollBack();
            }
        } catch (Exception var13) {
            var13.printStackTrace();
            LogUtil.log("参数错误",var13);
            DbConnection.rollBack();
            writer.print(JsonProcess.respError("参数错误"));
        }

    }
    public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.addHeader("Access-Control-Allow-Headers", "*");
        resp.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT");
    }
}
